package yto.freemarker.springbootstudy;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger2的配置类
 *
 * @author dongxing
 * @create 2018-04-09 14:33
 **/
@Configuration
@EnableSwagger2
public class Swagger2 {

//    @Bean
//    public Docket createRestApi() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .apiInfo(apiInfo())
//                .select().paths(Predicates.or( //这里添加你需要展示的接口
//                        PathSelectors.ant("/account/**"),
//                        PathSelectors.ant("/xxx/**"),
//                        PathSelectors.ant("/qqq/**"),
//                        PathSelectors.ant("/eee/**")
//                        )
//                ).build();
//    }
//
//    private ApiInfo apiInfo() {
//        return new ApiInfoBuilder()
//                .title("API平台名字").description("说明RESTful APIs").contact(new Contact("dx","dx","dx"))
//                .version("1.0").build();
//    }

//    @Bean
//    public Docket api() {
//        return new Docket(DocumentationType.SWAGGER_2)
//                .select()  // 选择那些路径和api会生成document
//                .apis(RequestHandlerSelectors.any()) // 对所有api进行监控
//                .paths(PathSelectors.any()) // 对所有路径进行监控
//                .build();
//    }

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("yto.freemarker.springbootstudy"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("SpringBoot 中使用Swagger构建Restful APIs")
                .description("更多SpringBoot 请查看官网")
                .termsOfServiceUrl("https://swagger.io/")
                .version("1.0")
                .build();
    }
}
